package com.yt;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)//免配置数据库
@EnableDiscoveryClient//zookeeper发现服务
@RestController
public class ConsulConsumer80 {
    @Resource
    RestTemplate restTemplate;
    @RequestMapping("/")
    public String show(){
        String url="http://consul-provider";
        String res= restTemplate.getForObject(url+"/me",String.class);
        return res+ "ok";
    }

    @Bean
    //使用服务名称后需要添加负载均衡
    @LoadBalanced
    public RestTemplate getRestTemplate(){
        return new RestTemplate();
    }
    public static void main(String[] args) {
        SpringApplication.run(ConsulConsumer80.class, args);
    }

}
